//
//  SsehInvoiceTitleTableViewCell.m
//  customer
//
//  Created by 杨阳 on 2018/11/1.
//  Copyright © 2018 yinlong. All rights reserved.
//

#import "SsehInvoiceTitleTableViewCell.h"

@interface SsehInvoiceTitleTableViewCell ()

@property (nonatomic,strong) NSIndexPath * tIndex;

@end

@implementation SsehInvoiceTitleTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.defaultButton.layer.cornerRadius = 8.0f;
    self.defaultButton.layer.borderColor = RGBColor(178, 178, 178).CGColor;
    
    UITapGestureRecognizer * editTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(editClick)];
    [self.editImageView addGestureRecognizer:editTap];
    
    UITapGestureRecognizer *editLabeTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(editClick)];
    self.editLabel.userInteractionEnabled = YES;
    [self.editLabel addGestureRecognizer:editLabeTap];
    
    UITapGestureRecognizer * delTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(delClick)];
    [self.delImageView addGestureRecognizer:delTap];
    
    UITapGestureRecognizer *delLabelTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(delClick)];
    self.delLabel.userInteractionEnabled = YES;
    [self.delLabel addGestureRecognizer:delLabelTap];
}

-(void)editClick{
    
    if (_editHandle) {
        _editHandle(@"编辑",self.tIndex);
    }
}

-(void)delClick{
    
    if (_delHandle) {
        _delHandle(@"删除",self.tIndex);
    }
}

- (IBAction)defaultButtonClick:(id)sender {
    
    if (_defaultHandle) {
        if (!self.defaultButton.selected) {
            _defaultHandle(@"默认抬头",self.tIndex);
        }
        
    }
    
}


-(void)configData:(InvoiceModel *)model andIndex:(NSIndexPath *)index{
    
    self.tIndex = index;
    
    if ([model.invoice_type isEqualToString:@"1"]) {
        self.topLabel.text = [NSString emptyStr:model.invoice_name];
    }else{
        self.topLabel.text = [NSString emptyStr:model.invoice_company_name];
    }
    if ([model.is_default isEqualToString:@"1"]) {
        self.defaultButton.selected = YES;
        self.defaultButton.layer.borderWidth = 0.0f;
    }else{
        self.defaultButton.selected = NO;
        self.defaultButton.layer.borderWidth = 1.0f;
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
